package com.cy.aircompressor.main.home.other;

import android.graphics.Color;
import android.os.Bundle;
import android.view.WindowManager;

import androidx.fragment.app.FragmentManager;

import com.cy.aircompressor.config.AirConfig;
import com.cy.aircompressor.databinding.DialogWarningDetailLayoutBinding;
import com.cy.aircompressor.entity.warning.WarningMsg;
import com.jakewharton.rxbinding2.view.RxView;
import com.net.model.base.fragment.BaseVBDialogFragment;

import java.util.concurrent.TimeUnit;

public class WarningDetailFragment extends BaseVBDialogFragment<DialogWarningDetailLayoutBinding> {
    private WarningMsg warningMsg;

    public static WarningDetailFragment showDialogFragment(FragmentManager fragmentManager, String tag, WarningMsg warningMsg) {
        Bundle args = new Bundle();
        WarningDetailFragment fragment = new WarningDetailFragment();
        args.putSerializable("warningMsg", warningMsg);
        fragment.setArguments(args);
        fragment.show(fragmentManager, tag);
        return fragment;
    }

    @Override
    protected DialogWarningDetailLayoutBinding getViewBinding() {
        return DialogWarningDetailLayoutBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void initData() {
        warningMsg = (WarningMsg) getArguments().getSerializable("warningMsg");
        mBinding.powerStationName.setText(AirConfig.get().userInfo.getPowerStationName());
        mBinding.compressorName.setText(warningMsg.getCompressorName());
        mBinding.compressorModel.setText(warningMsg.getCompressorModel());
        mBinding.compressorPartDesc.setText(warningMsg.getCompressorPartDesc());
        mBinding.compressorPointDesc.setText(warningMsg.getCompressorPointDesc());
        mBinding.sensorName.setText(warningMsg.getSensorName());
        mBinding.sensorType.setText(warningMsg.getSensorType().toString());
        mBinding.value.setText(warningMsg.getValue() + "");
        mBinding.status.setText(warningMsg.getStatus() == 1 ? "已处理" : "未处理");
        mBinding.status.setTextColor(Color.parseColor(warningMsg.getStatus() == 1 ? "#15CB22" : "#F04538"));
        mBinding.createTime.setText(warningMsg.getCreateTime());
        mBinding.updateTime.setText(warningMsg.getUpdateTime());
        mBinding.alarmRules.setText(warningMsg.getAlarmRules());
        RxView.clicks(mBinding.closeBtn)
                .throttleFirst(500, TimeUnit.MILLISECONDS)
                .subscribe(o -> {
                    dismiss();
                });
    }

    @Override
    protected void requestNetwork() {
    }


    @Override
    protected int getWindowHeight() {
        return WindowManager.LayoutParams.WRAP_CONTENT;
    }

    @Override
    protected int getWindowWidth() {
        return getScreenWidth() *2/ 5;
    }

    @Override
    protected void initialize() {

    }

}
